<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改标准仓库')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dw-edit" th:object="${etlDrawDw}">
            <input name="idDw" th:field="*{idDw}" type="hidden">
            <input type="hidden" name="sdDwcls" id="sdDwcls" th:field="*{sdDwcls}" />
            <div class="form-group">    
                <label class="col-sm-2 control-label">表名：</label>
                <div class="col-sm-8">
                    <input name="cdTb" th:field="*{cdTb}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">表描述：</label>
                <div class="col-sm-8">
                    <input name="na" th:field="*{na}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">分类：</label>
                <div class="col-sm-8">
                    <input onclick="selectDwClsTree()" name="naDwcls" id="naDwcls" th:field="*{naDwcls}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">启用标志：</label>
                <div class="col-sm-8">
                    <input name="fgAct" th:field="*{fgAct}" class="form-control" type="text">
                </div>
                <div class="col-sm-2">
                    <button type="button" class="btn btn-info btn-sm" onclick="dwSqlValid()"> 校验 </button>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">抽取类型：</label>
                <div class="col-sm-8">
                    <select name="euExecType" class="form-control">
                        <option value="date" th:selected="*{euExecType=='date'}">日期</option>
                        <option value="all" th:selected="*{euExecType=='all'}">全量</option>
                        <option value="self" th:selected="*{euExecType=='self'}">自定义</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">删除sql：</label>
                <div class="col-sm-10">
                    <textarea rows="4" name="sqlDel" id="sqlDel" class="form-control">[[*{sqlDel}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">查询sql：</label>
                <div class="col-sm-10">
                    <textarea rows="20" name="sqlQry" id="sqlQry" class="form-control">[[*{sqlQry}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "base/etl/dw";
        $("#form-dw-edit").validate({
            focusCleanup: true
        });
        /* 用户管理-新增-选择部门树 */
        function selectDwClsTree() {
            var url = ctx + "base/label/tree?sdCls=dw";
            var options = {
                title: '选择标签',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            debugger;
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = $.modal.getChildFrame(index);
            $("#naDwcls").val(body.find('#treeName').val());
            $("#sdDwcls").val(body.find('#treeId').val());
            $.modal.close(index);
        }
        function dwSqlValid() {
            $.ajax({
                url:prefix+"/dwSQlValid",
                cache: false,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify({"sqlQry":$("#sqlQry").val()}),
                contentType: 'application/json;charset=UTF-8',
                success: function (data) {
                    debugger;
                    if(data.code=="0") {
                        $.modal.alertSuccess("验证通过");
                    } else {
                        $.modal.alertError(data.msg==null?"SQL语句无法执行":data.msg);
                    }
                }
            });
        }
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-dw-edit').serialize());
            }
        }

        $("input[name='dtSysCre']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='dtSysModi']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>